package org.codeart.consumer.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.codeart.producer.api.HelloApi;
import org.codeart.producer.dubbo.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    
    @Autowired
    private HelloApi helloApi;

    @DubboReference
    private HelloService helloService;

    @GetMapping("/hello")
    public ResponseEntity<String> hello() {
        System.out.println("consumer calls producer");
        return helloApi.hello();
    }
    
    @GetMapping("/hello-dubbo")
    public ResponseEntity<String> helloDubbo() {
        System.out.println("consumer calls producer by dubbo");
        return ResponseEntity.ok(helloService.hello());
    }

}
